<?php
namespace app\mobile\controller;

use app\model\Theme; 
use app\model\Poster; 
use app\model\Worker; 
use app\model\Order; 

class WIndex extends Base
{
    public function W_index()
    {
global $_G, $_P;
$fans = $this->checkuser();
$themeid = intval($_P['themeid']);
if($themeid < 0){
	return_msg('管理后台地址不正确');
}
$system=$_G['system'];
$theme = Theme::getThemeById($themeid);
$config = 	Theme::getConfig($themeid);
if(empty($theme['id'])){
	return_msg('管理后台地址不正确');
}
if (empty($theme['softsn'])) {
	return_msg('软件未激活,请联系' . $_G['companyname'] . '工作人员');
}
$myworker = Worker::getThemeWorkerByOpenidNew($_G['openid'],$themeid);
if(!($system['ruanjian']!=3 || $config['showshop']==0 || ($system['ruanjian']==3 && $config['showshop']==$myworker['company']))){
	$myworker = "";
}
if (empty($myworker)) {
	return_msg('您不是员工,无权访问');
}
$msg = Worker::gethoutaistats();
if (!empty($msg)) {
	return_msg($msg);
}

$wx = $_G['platform']['jssdkconfig']; 

$do = 'index';
	//数据统计
if ($myworker['level'] == '1'){
	//删除重复员工
	Worker::WorkerDeleteChongfu($themeid);

		$recordcount = intval(db_fetchcolumn ( 'SELECT COUNT(*) FROM ' . tablename ( t_record ) . "
				WHERE  themeid = '{$themeid}' and status > 0  and status!=3" ));
		$recordxxcount = intval(db_fetchcolumn ( 'SELECT COUNT(*) FROM ' . tablename ( t_record ) . " as r
			WHERE r.themeid ='{$themeid}'  and r.status = '3' " ));
		$fanscount = intval(db_fetchcolumn ( 'SELECT COUNT(*) FROM ' . tablename ( t_fans ) . "
				WHERE themeid = '{$themeid}' " ));
		$ordercount = floatval(db_fetchcolumn ( 'SELECT sum(realfee) FROM ' . tablename ( t_order ) . "
				WHERE themeid = '{$themeid}' and paystate = 1 and realfee > 0 " ));
		$ordercount = sprintf("%.2f", $ordercount);

		$commcount = floatval(db_fetchcolumn ( 'SELECT sum(fee) FROM ' . tablename ( t_comm ) . "
            WHERE themeid ='{$themeid}'  and status  = 1 " ));
		$commcount = -sprintf("%.2f", $commcount);
}
$shouxu = 1 - Order::shouxufei();
$shouxu2 = Order::shouxufei();

	$sharedata = array(
	    'themeid'=>$themeid,
	    'fopenid'=>$_G['openid'],
	    'fromuid'=>$_G['member']['uid'],
	    'workerid'=>$myworker['uid'],
	    'flag'=>1,
	);
    if ($system['gongzhong'] =='1'){
    	$domaintxt = $system['domainhead1'];
    }else{
    	$domaintxt = DOMAIN0;
    }
	$workerurl = $_G['url_scheme'].$domaintxt."/".createMobileUrl('index',$sharedata);

	$workerurl = Poster::GetWorkerUrl($system,$workerurl,MODULE_NAME ."员工:".$myworker['username']);
	
if($_G['companyname'] =='新飞驰软件'){
	$return_clicent = get_defined_vars();
return view('/fcworker/fc_index' , $return_clicent);
}else{
	$return_clicent = get_defined_vars();
return view('/yxworker/w_index' , $return_clicent);
}
}
}